package me.ingxin.android.permission2.task

import android.content.Context
import me.ingxin.android.permission2.Callback
import me.ingxin.android.permission2.permissionGranted
import me.ingxin.android.permission2.specialPermissionGranted

/**
 * Created on 2023/7/8 by yin
 */
internal class PermissionResultChecker(private val callback: Callback) {

    /**
     * 检查权限结果并执行回调
     * @param context 上下文
     * @param specialPermissions 请求的特殊权限
     * @param normalPermissions 请求的普通权限
     */
    fun check(context: Context, normalPermissions: List<String>, specialPermissions: List<String>) {
        val deniedList = ArrayList<String>()
        val grantedList = ArrayList<String>()
        normalPermissions.forEach {
            if (context.permissionGranted(it)) {
                grantedList.add(it)
            } else {
                deniedList.add(it)
            }
        }

        specialPermissions.forEach {
            if (context.specialPermissionGranted(it)) {
                grantedList.add(it)
            } else {
                deniedList.add(it)
            }
        }

        callback.onResult(deniedList.isEmpty(), grantedList, deniedList)
    }

}